<?php require_once '../includes/includes.php'; ?>
<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
        <style>
            #info {
                font-weight: bold;
            }
        </style>
    </head>
    <body>
        <p>
            <a href="#" id="createAlbum">Create new Album</a>
            <br />
            <a href="counter/index.php" >Set Counter</a>
            <div id="saveAlbum" style="display: none;">
                <p>
                    Album name:<br />
                    <input type="text" id="album" />
                </p>
                <p>
                    Alt:<br />
                    <input type="text" id="alt" />
                </p>
                <p>
                    Content:<br />
                    <input type="text" id="content" />
                </p>
                <input type="button" id="create" value="Create" />
            </div>
            <div id="info"></div>
        </p>
        <h2>Albums</h2>
        <?php
            $albums = getAlbums();

            foreach ($albums as $album) {
                if ($album['id'] == 1) {
                    continue;
                }
                else if(is_dir('../albums/' . $album['name'])) {
                    echo '<li><a class="folder" href="view/album.php?id=' . $album['id'] . '">' . $album['name'] . '</a></li>';
                }
            }
        ?>
        <script type="text/javascript">
            $('#createAlbum').click(function() {
                $('#saveAlbum').show();

                $('#create').click(function() {

                    var album = $('#album').val();
                    var alt = $('#alt').val();
                    var content = $('#content').val();
                    var keepOn = true;

                    $.ajax({
                        url:  'view/createAlbum.php',
                        type: "POST",
                        data: { album : album, alt : alt, content : content },
                        success: function (res) {
                            if(res.length) {
                                $('#info').html(res);
                                keepOn = false;
                            }
                        }
                    }).done(function() {
                        if(keepOn == true) {
                            location.reload();
                        }
                    });
                });
            });
        </script>
</body>
</html>

